package com.lanjiu.lib.imclient.dto;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description: 好友
 * @author: Panwei
 * @date: 2019/11/14 16:23
 */
public class FriendDto extends Dto {

    // 当前用户类型
    private String currentUserType;

    // 好友ID
    private String friendId;

    // 好友用户ID
    private String friendUserId;

    // 好友昵称
    private String friendNickname;

    // 好友头像
    private String friendAvatar;

    // 好友备注
    private String friendAlias;

    // 好友用户类型
    private String userType;

    // 在线状态
    private String onlineStatus;

    // 是否接收离线消息
    private boolean offlineMessage;

    // 阅后即焚
    private boolean snapchatStatus;

    // 阅后即焚时长
    private int snapchatTimeLength;

    // 阅后即焚时间单位
    private int snapchatTimeUnit;

    public FriendDto(String currentUserType) {
        this.currentUserType = currentUserType;
    }

    public String getCurrentUserType() {
        return currentUserType;
    }

    public void setCurrentUserType(String currentUserType) {
        this.currentUserType = currentUserType;
    }

    public String getFriendId() {
        return friendId;
    }

    public void setFriendId(String friendId) {
        this.friendId = friendId;
    }

    public String getFriendUserId() {
        return friendUserId;
    }

    public void setFriendUserId(String friendUserId) {
        this.friendUserId = friendUserId;
    }

    public String getFriendNickname() {
        return friendNickname;
    }

    public void setFriendNickname(String friendNickname) {
        this.friendNickname = friendNickname;
    }

    public String getFriendAvatar() {
        return friendAvatar;
    }

    public void setFriendAvatar(String friendAvatar) {
        this.friendAvatar = friendAvatar;
    }

    public String getFriendAlias() {
        return friendAlias;
    }

    public void setFriendAlias(String friendAlias) {
        this.friendAlias = friendAlias;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getOnlineStatus() {
        return onlineStatus;
    }

    public void setOnlineStatus(String onlineStatus) {
        this.onlineStatus = onlineStatus;
    }

    public boolean isOfflineMessage() {
        return offlineMessage;
    }

    public void setOfflineMessage(boolean offlineMessage) {
        this.offlineMessage = offlineMessage;
    }

    public boolean isSnapchatStatus() {
        return snapchatStatus;
    }

    public void setSnapchatStatus(boolean snapchatStatus) {
        this.snapchatStatus = snapchatStatus;
    }

    public int getSnapchatTimeLength() {
        return snapchatTimeLength;
    }

    public void setSnapchatTimeLength(int snapchatTimeLength) {
        this.snapchatTimeLength = snapchatTimeLength;
    }

    public int getSnapchatTimeUnit() {
        return snapchatTimeUnit;
    }

    public void setSnapchatTimeUnit(int snapchatTimeUnit) {
        this.snapchatTimeUnit = snapchatTimeUnit;
    }

    public FriendDto(BusinessProtocolEntities.TouristsFriend friend) {
        this.currentUserType = IMSContacts.UserType.TOURISTS_USER;
        this.friendId = friend.getFriendId();
        this.friendUserId = friend.getFriendUserId();
        this.friendNickname = friend.getFriendNickname();
        this.friendAvatar = friend.getFriendAvatar();
        this.friendAlias = friend.getFriendAlias();
        this.userType = friend.getUserType();
        this.onlineStatus = friend.getOnlineStatus();
        BusinessProtocolEntities.Settings settings = friend.getSettings();
        if (null != settings) {
            this.offlineMessage = settings.getOfflineMessage();
            this.snapchatStatus = settings.getSnapchatStatus();
            this.snapchatTimeLength = settings.getSnapchatTimeLength();
            this.snapchatTimeUnit = settings.getSnapchatTimeUnit();
        }
    }

    public FriendDto(BusinessProtocolEntities.RegisteredFriend friend) {
        this.currentUserType = IMSContacts.UserType.REGISTERED_USER;
        this.friendId = friend.getFriendId();
        this.friendUserId = friend.getFriendUserId();
        this.friendNickname = friend.getFriendNickname();
        this.friendAvatar = friend.getFriendAvatar();
        this.friendAlias = friend.getFriendAlias();
        this.userType = friend.getUserType();
        this.onlineStatus = friend.getOnlineStatus();
        BusinessProtocolEntities.Settings settings = friend.getSettings();
        if (null != settings) {
            this.offlineMessage = settings.getOfflineMessage();
            this.snapchatStatus = settings.getSnapchatStatus();
            this.snapchatTimeLength = settings.getSnapchatTimeLength();
            this.snapchatTimeUnit = settings.getSnapchatTimeUnit();
        }
    }

    @Override
    public Object toProtobuf() {
        if (IMSContacts.UserType.REGISTERED_USER.equals(currentUserType)) {
            BusinessProtocolEntities.RegisteredFriend.Builder builder = BusinessProtocolEntities.RegisteredFriend.newBuilder();
            if (null != friendId) builder.setFriendId(friendId);
            if (null != friendUserId) builder.setFriendUserId(friendUserId);
            if (null != friendNickname) builder.setFriendNickname(friendNickname);
            if (null != friendAvatar) builder.setFriendAvatar(friendAvatar);
            if (null != friendAlias) builder.setFriendAlias(friendAlias);
            if (null != userType) builder.setUserType(userType);
            if (null != onlineStatus) builder.setOnlineStatus(onlineStatus);
            return builder.setSettings(BusinessProtocolEntities.Settings.newBuilder()
                    .setOfflineMessage(offlineMessage)
                    .setSnapchatStatus(snapchatStatus)
                    .setSnapchatTimeLength(snapchatTimeLength)
                    .setSnapchatTimeUnit(snapchatTimeUnit)
                    .build())
                    .build();
        } else {
            BusinessProtocolEntities.TouristsFriend.Builder builder = BusinessProtocolEntities.TouristsFriend.newBuilder();
            if (null != friendId) builder.setFriendId(friendId);
            if (null != friendUserId) builder.setFriendUserId(friendUserId);
            if (null != friendNickname) builder.setFriendNickname(friendNickname);
            if (null != friendAvatar) builder.setFriendAvatar(friendAvatar);
            if (null != friendAlias) builder.setFriendAlias(friendAlias);
            if (null != userType) builder.setUserType(userType);
            if (null != onlineStatus) builder.setOnlineStatus(onlineStatus);
            return builder.setSettings(BusinessProtocolEntities.Settings.newBuilder()
                    .setOfflineMessage(offlineMessage)
                    .setSnapchatStatus(snapchatStatus)
                    .setSnapchatTimeLength(snapchatTimeLength)
                    .setSnapchatTimeUnit(snapchatTimeUnit)
                    .build())
                    .build();
        }
    }
}
